import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/handle/xindong_common_handle.dart';
import 'package:xindong/manager/xindong_tencent_singleton.dart';
import 'package:xindong/manager/xindong_user_controller.dart';
import 'package:xindong/routes/tab_bar/xindong_tab_bar_controller.dart';
import 'package:xindong/routes/tab_mine/xindong_wode_http.dart';
import 'package:xindong/widgets/dialog/xindong_today_fate_dialog.dart';

class XinDongTabBarYeMian extends StatefulWidget {
  const XinDongTabBarYeMian({super.key});

  @override
  State<XinDongTabBarYeMian> createState() => _XinDongTabBarYeMianState();
}

class _XinDongTabBarYeMianState extends State<XinDongTabBarYeMian> {
  final _mineHandle = XinDongWoDeHandle();

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
      XinDongCommonHandle().chatCommonWords();
      XinDongTencentSingleton.instance.getCustomer();
      await XinDongUserController.to.requestUserInfo();
      _mineHandle.resetPush();
      _mineHandle.setOnline();
      _mineHandle.setVersion();
      // 每日重置（登录成功到TabBar调用，每次到前台调用，某些操作需要requestUserInfo获取用户信息才实现）
      XinDongTodayFateDialog.show();
    });
  }

  @override
  Widget build(BuildContext context) {
    final tabBarProvider = Get.put(XinDongTabBarController());
    tabBarProvider.onInit();

    return Scaffold(
      body: PageView(
        physics: const NeverScrollableScrollPhysics(),
        scrollDirection: Axis.horizontal,
        controller: tabBarProvider.yemianController,
        children: tabBarProvider.tabList.map((model) => model.yemian).toList(),
      ),
      bottomNavigationBar: Obx(
        () => BottomAppBar(
          height: kTabBarHeight,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: tabBarProvider.tabBarItemList,
          ),
        ),
      ),
    );
  }
}
